package com.be.beadmin.basicData.entity;

import com.be.beadmin.common.entity.BaseEntity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author chenwei
 * @date 2/24/2023 3:46 PM
 * 菜单权限
 */
@Getter
@Setter
@Entity
@Table(name="SYS_MENU")
public class Menu extends BaseEntity {
    @Column(name = "CODE",columnDefinition = "VARCHAR(30) COMMENT '菜单编码' ")
    private String code;

    @Column(name = "NAME",columnDefinition = "VARCHAR(30) COMMENT '菜单名称' ")
    private String name;

    /**
     * 父级菜单
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "PARENT_ID",columnDefinition = "VARCHAR(32) COMMENT '父菜单' ")
    private Menu parentMenu;


    @Column(name = "TYPE",columnDefinition = "decimal(1) COMMENT '菜单类别：0-web；1-app' ")
    private Integer type;


    @JsonBackReference
    @ManyToMany(mappedBy = "menus"
//            ,fetch=FetchType.EAGER //放弃维权
    )
    private Set<Role> roles = new HashSet<>();

    // 添加菜单号
    @Column(name = "SEQ",columnDefinition = "decimal(3) COMMENT '同父菜单顺序' ")
    private Integer seq;


    @OneToMany(mappedBy = "parentMenu", fetch = FetchType.LAZY)
    @OrderBy("seq ASC")
    private List<Menu> childMenus = new ArrayList<>();
}
